Finder Liaison sends AppleEvents to the Finder. Requires System 7 or later.
Usage:
The System 7 Finder supports the Finder Suite of AppleEvents. Unfortunately, there is no way to explicitly send AppleEvents to the Finder from AppleScript. Finder Liaison acts as an intermediary between AppleScript and the Finder.
Distribution:
Finder Liaison is copyrighted, but free, commonly called Freeware. The author retains all rights to the program, but specifically allows redistribution via the following channels:
(1) The disk associated with the book "The Tao of AppleScript" by BMUG
(2) Non-commercial bulletin board services
(3) The following commercial BBS's: America Online, CompuServe, AppleLink
(4) Internet archives and file servers
(5) Disk libraries of non-profit organizations
(6) Free exchange between individuals
In all cases, this ReadMe file must accompany the program.
For-profit companies that sell software programs must receive explicit written permission from the author before distributing the program.
1.0 11-Jun-93 Ships with "The Tao of AppleScript" book by BMUG
1.1b1 23-Aug-93 Supports full path names for files and folders
1.1b2 05-Oct-93 Updates Finder display when changing the Creator/Type/Name
of a File/Folder which is in an open window
1.1b3 07-Oct-93 Supports creating new folders
1.1 10-Nov-93 New release
• AppleEvents supported by Finder Liaison:
Show About This Mac
Empty Trash
Restart
Show Clipboard
Shut Down
Sleep
Close Window of <Folder or Disk>
Print Window of <Folder or Disk>
Page Setup for <Folder or Disk>
Example: Close Window of Folder "Documents" of Disk "HD80"
Open <File or Folder or Disk>
Duplicate <File or Folder or Disk>
Get Info for <File or Folder or Disk>
Make Alias of <File or Folder or Disk>
Print <File or Folder or Disk>
Put Away <File or Folder or Disk>
Reveal <File or Folder or Disk>
Show Sharing for <File or Folder or Disk>
Examples: Open File “Letter” of Folder “Correspondence” of Disk “Personal”
Put Away Disk “Floppy”
Duplicate File “abc” of Folder “Desktop Folder” of Disk “HD20”
Note: This is how to refer to a File/Folder on the Desktop
Set View of <Folder or Disk> to <view option>
<view option> may be: by Small Icon, by Icon, by Name, by Date, by Size, by Kind, by Comment, by Label, by Version
Example: Set View of Folder "Icons" of Disk "Art" To by Name
Move Window of <Folder or Disk> To <location>
<location> is the {left,top} position
Example: Move Window of Folder "Programs" of Disk "HD40" To {200,50}
Set Window Size of <Folder or Disk> to <size>
<size> is {width,height}
Example: Set Window Size of Disk “My Drive” To {500, 300}
Zoom Out Window of <Folder or Disk>
Zoom In Window of <Folder or Disk>
Example: Zoom In Window of Folder “xx” of Folder “yy” of Disk “zz”
Move <File or Folder of Disk> To <Folder or Disk> [At <location>]
Drag Copy of <File or Folder of Disk> To <Folder or Disk> [At <location>]
<location> is an optional parameter specifying the {top,left} position
Example: Move File “script” of Disk “HD40” To Folder “xx” of Disk “HD40” At {10, 50}
Drag Copy of Folder “tables” of Disk “Drive” To Folder “x” of Disk “Drive”
* The optional <location> parameter is supposed to specify where in the window to move/drag the icons. However, it doesn’t appear to work in a consistent or understandable manner.
Set Creator of <File> To <ostype>
Set Type of <File> To <ostype>
<ostype> is a four-character code (it is an error if <ostype> is not exactly four characters)
Example: Set Creator of File “letter” of Disk “HD80” To “MSWD”
Get Creator of <File>
Get Type of <File>
returns Creator/Type code of the specified file as a four-character string
Example: Get Creator of File “spreadsheet” of Folder “docs” of Disk “mine”
Set Name of <File or Folder of Disk> To <Name>
Example: Set Name of File “untitled” of Disk “HD40” To “My Letter”
Get Path of <File or Folder of Disk>
returns the full pathname for the specified item. Does not matter if item exists or not (since you many want to use this pathname to create a new file).
Example: Get Path of File “script” of Folder “stuff” of Disk “HD160”
Create <File or Folder> [replacing <yes/no>]
creates an empty File (with both data and resource forks). The optional 'replacing' parameter specifies whether to replace the file if it already exists. The default is no.
Example: Create File “Empty” of Folder “Docs” of Disk “HD20” replacing yes
The 'replacing' parameter is not supported for folders, and it is an error to use
'replacing' when creating a folder.
Example: Create Folder "Papers" of Disk "HD80"
Get Files in <Folder of Disk>
returns a list of the names of the Files in the specified Folder or Disk. Not full pathnames, just the file names.
Example: Get Files in Folder “Letters” of Disk “HD50”
Get Folders in <Folder of Disk>
returns a list of the names of the Folders in the specified Folder or Disk . Not full pathnames, just the folder names.
Example: Get Folders in Folder “Applications” of Disk “HD60”
• Specifying Files, Folders, or Disks
You can specify a File by a container list, such as:
File "agenda" of Folder "Documents" of Folder "Personal" of Disk "HardDrive"
Or, you can use a full path name, which for the same example as above is:
"HardDrive:Personal:Documents:agenda"
A full path name specifies the names in the reverse order, separating folder and disk names with a colon (":").
The same holds true for Folders. Here is an example container list:
Folder "Notes" of "Folder "Meetings" of Disk "Accounting"
And here is the same folder as a full path name:
"Accounting:Meetings:Notes:"
The colon at the end is *very* important. That's how you distinguish a folder from a file. In a full path name, you can think of a folder or disk name as including the trailing colon.
For Disks, there isn't much difference between a container list and a full path. The container list specification doesn't have a colon, the full path name does.
Container List: Disk "My Floppy"
Full Path Name: Disk "My Floppy:"
Normally, you should use the container list form in your scripts, However, the full path name form is needed when accessing files from the list of items returned by the "on open" message. You use this message to create script applications with drag-and-drop capability (called a "droplet"). The string representation of an item from the list returned by "on open" is a full path name. You can distinguish files from folders/disks by checking if the string ends with a colon (file names don't end with a colon; folder and disk names do end with a colon).
Here is an example script for a droplet that operates on the items dropped on it by creating aliases of folders and disks and duplicating files:
on open (theItems)
tell application "Finder Liaison 1.1"
repeat with currItem in theItems
copy (currItem as string) to pathName
if pathName ends with ":" then
-- item is a folder or disk, create an Alias
Make Alias of Folder pathName
else
-- item is a file, Duplicate it
Duplicate File pathName
end if
end repeat
end tell
end open
Note that it's OK to refer to all path names ending with a colon as Folders, even though they may actually be disks. Finder Liaison treats Folders and Disks the same; they both are containers of (other) folders and files.